package fw.qaz.asmx.reader.adapter.item;


import java.util.ArrayList;
import java.util.Arrays;

public class BookMarkItem
{

    //书签的结构------------------------不知道写在这里到底合不合理。。。。
    public String path = ""; //书路径，标示符

    //这三个是生死同步的
    private ArrayList<Integer> ids = new ArrayList<>();
    private ArrayList<String> comments = new ArrayList<>();
    private ArrayList<Integer> progresss = new ArrayList<>();

    public BookMarkItem()
    {

    }

    public BookMarkItem(int id, String path, String comment, int progress)
    {
        this.path = path;
        this.addMark(id, comment, progress);
    }

    //检查添加
    public boolean addMark(int id, String comment, int progress)
    {
        if (this.ids.contains(id))
        {
            return false;
        }
        ids.add(id);
        comments.add(comment);
        progresss.add(progress);

        return true;
    }

    //获取最新的进度
    public long getMaxProgress()
    {
        Long[] arrays = progresss.toArray(new Long[progresss.size()]);
        Arrays.sort(arrays);
        return arrays[arrays.length - 1];
    }

    public int getMarksSize()
    {
        return progresss.size();
    }

    public int getid(int index)
    {
        return this.ids.get(index);
    }

    public String getComment(int index)
    {
        return comments.get(index);
    }

    public long getProgress(int index)
    {
        return progresss.get(index);
    }

    //删除制定位置上的书签
    public void removeMarkById(int id)
    {
        for (int i = 0; i < ids.size(); i++)
        {
            if (ids.get(i) == id)
            {
                ids.remove(i);
                comments.remove(i);
                progresss.remove(i);
            }
        }
    }

    //修改制定位置上的书签
    public void renameComment(int id, String newComment)
    {

        for (int i = 0; i < ids.size(); i++)
        {
            if (ids.get(i) == id)
            {
                comments.add(i + 1, newComment);//先加再删
                comments.remove(i);
            }
        }
    }
}
